=detailed view=

==software design==

Our program to find its way out of a maze consists of three main methods. A callibration, 
a line following and a maze following method.

===callibrate()===
The callibration method finds the value for a white and a black background. It reads the 
value of both sensors and then calculates the mean value of it. By pressing escape you can 
go from white to black.

===followLine()===
The line following algorithm uses one sensor (the left) to detect the line. When it hits a black spot 
the robot goes to the right (for half a second) and when it hits a white spot it goes to the left.

===followmaze()===
The maze following is the main part of the program. It detects the lines and the crossroads. When 
there is only a line, it goes to followLine(). When it detects a crossroad to the right, the 
robot steers right. If both sensors detect a white spot, it means that the robot has reached 
a dead end and it will turn around.




== improvements==

First assumption of our algorithm is that robot will find his way out by turning right on every crossroad. 
This can be easily seen by  representing maze as a tree: taking always right turns corresponds to going 
around the tree on right side first.


When the path is found, we need to eliminate all dead-ends. We'll create two arrays of charactes (or integers): 
GOOD {R. D}  (where R is right and D is dead-end) and BETTER {R, L, A}  (right, left, ahead) *. 
In first passing we'll try to detect where the turning right are and where the dead-ends are. Still, 
we should be careful because there are some''fake state'' - when robot believes he's on the dead-end 
but in fact both sensors detect white just for a moment. Therefore, we shall count only these states 
that last longer than 5 seconds.
After doing it, we have a code of characters, for example RDRDRRRDR. The problem that arises is that 
symbol for dead-end is DR, and for going left RDR (not all actions are determined). We solve it by measuring
 time needed for DR. If it takes less than 20 seconds - it is a dead-end, otherwise it's turning left. 
Where the crossroads are is detected using timer (of course, all time spent on paths that end with 
dead-ends is subtracted ). 
Now our robot is ready to find a shorter way . 

*the value A will never be used because it's robot's default state.
